package cronTask

import (
	"fmt"
	"github.com/shirou/gopsutil/v3/cpu"
	mem2 "github.com/shirou/gopsutil/v3/mem"
	"runtime"
	"runtime/pprof"
	"time"
)

type Demo struct {
}

func init() {
	ReginCronStruct["demo"] = &Demo{}
	ReginCronStruct["demo1"] = &Demo1{}
}

func (d Demo) RunCron() func() {
	return func() {
		fmt.Println(222222)
	}
}

type Demo1 struct {
}

func (d Demo1) RunCron() func() {
	return func() {
		p, c := cpu.Percent(time.Second, false)
		if c != nil {
			fmt.Println(c.Error())
		}
		fmt.Println("cpu", p[0])

		mem, err := mem2.VirtualMemory()
		if err != nil {
			fmt.Println(err.Error())
		}
		fmt.Println("mem", mem.UsedPercent)
		threadCount := pprof.Lookup("threadcreate").Count()
		//Goroutine数
		fmt.Println(threadCount)
		gNum := runtime.NumGoroutine()
		fmt.Println(gNum)
	}
}
